import 'package:flutter/material.dart';

class AlertDialogDemo extends StatelessWidget {
  const AlertDialogDemo({super.key});

  void _showDialog(context, widget) {
    showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
            title: const Text("标题"),
            content: widget,
            actions: <Widget>[
              TextButton(
                  onPressed: () {
                    print("=====取消");
                    Navigator.pop(context, "取消");
                  },
                  child: const Text("取消")),
              TextButton(
                  onPressed: () {
                    Navigator.pop(context, "确定");
                    print("=====确定");
                  },
                  child: const Text("确定"))
            ],
          );
        });
  }

  void _showTextDialog(context) {
    _showDialog(context, const Text('弹窗内容'));
  }

  void _showListDialog(context) {
    _showDialog(
      context,
      const SingleChildScrollView(
        child: ListBody(
          children: <Widget>[
            Text('This is a demo alert dialog.'),
            Text('Would you like to approve of this message?'),
          ],
        ),
      ),
    );
  }

  void _showAboutDialog(context) {
    showAboutDialog(
      context: context,
      applicationName: "123123"
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("AlertDialogDemo"),
      ),
      body: Container(
          alignment: Alignment.center,
          padding: const EdgeInsets.all(16),
          decoration: const BoxDecoration(color: Colors.black12),
          child: ListView(
            children: [
              TextButton(
                onPressed: () {
                  _showTextDialog(context);
                },
                child: const Text("显示文本弹窗"),
              ),
              TextButton(
                  onPressed: () {
                    _showListDialog(context);
                  },
                  child: const Text("显示列表弹窗")),
              TextButton(
                  onPressed: () {
                    _showAboutDialog(context);
                  },
                  child: const Text("显示AboutDialog"))
            ],
          )),
    );
  }
}
